load("@rules_rust//rust:defs.bzl", "rust_library")
load("//bazel:canisters.bzl", "rust_canister")
load("//bazel:defs.bzl", "rust_ic_test_suite")

package(default_visibility = ["//rs/nervous_system:default_visibility"])

DEPENDENCIES = [
    "@crate_index//:ic-cdk",
    "@crate_index//:candid",
    "@crate_index//:serde",
    # Keep sorted.
] + select({
    "@rules_rust//rust/platform:wasm32-unknown-unknown": [],
    "//conditions:default": [
        # Keep sorted.
        "//rs/nervous_system/temporary",
    ],
})

DEV_DEPENDENCIES = DEPENDENCIES + [
    # Keep sorted.
    "//rs/registry/subnet_type",
    "//rs/types/types",
    "@crate_index//:ic-cdk-timers",
] + select({
    "@rules_rust//rust/platform:wasm32-unknown-unknown": [],
    "//conditions:default": [
        # Keep sorted.
        "//rs/config",
        "//rs/nns/test_utils",
        "//rs/rust_canisters/canister_test",
        "//rs/state_machine_tests",
    ],
})

LIB_SRCS = glob(
    ["src/**"],
    exclude = ["src/**/*tests.rs"],
)

DEV_DATA = [
    ":long-message-canister",
]

DEV_ENV = {
    "LONG_MESSAGE_CANISTER_WASM_PATH": "$(rootpath :long-message-canister)",
}

rust_library(
    name = "long_message",
    srcs = LIB_SRCS,
    crate_name = "ic_nervous_system_long_message",
    version = "0.0.1",
    deps = DEPENDENCIES,
)

rust_ic_test_suite(
    name = "long_message_test",
    srcs = glob(
        ["tests/**/*.rs"],
        exclude = ["tests/test_canisters/*.rs"],
    ),
    data = DEV_DATA,
    env = DEV_ENV,
    deps = DEV_DEPENDENCIES,
)

rust_canister(
    name = "long-message-canister",
    testonly = True,
    srcs = ["tests/test_canisters/long_message_canister.rs"],
    proc_macro_deps = [],
    service_file = ":tests/test_canisters/empty.did",
    deps = DEV_DEPENDENCIES + [":long_message"],
)
